#ifndef SEMAPHORE_H_
#define SEMAPHORE_H_

#include <SDL.h>
#include <list>

namespace Lame3d
{
	class Semaphore
	{
		public:
			Semaphore(int initCount = 1);
			~Semaphore();
			
			class Lock
			{
				public:
					~Lock();
					
					bool operator*() const;
					
				protected:
					Lock(Semaphore &s, bool v);
					
					Semaphore &sem;
					bool valid;
					
				friend class Semaphore;
			};
			
			/** Acquire lock.  Values of timeout:
			 * 		< 0:	Wait forever
			 * 		0:		Return immediately
			 * 		> 0:	Wait the specified number of milliseconds
			 */
			Lock Wait(int timeout = -1);
			int Value();
					
		protected:
			SDL_sem *sdlSem;
		
		friend class Lock;	
	};
}

#endif /*SEMAPHORE_H_*/
